/**
    Copyright (c) 2010 yakiimo02
    Distributed under the New BSD License.
    See included license.txt or http://www.yakiimo3d.com/NewBSDLicense.txt
**/

#pragma once

#include "Nullstein/TaskScheduler.h"
#include "Nullstein/ParallelFor.h"

#include "optimized/SmallPtGeometryOPT.h"
#include "optimized/SmallPtStructs.h"
#include "optimized/SphereSOA.h"
 
#include <vector>

class DataBufferDX11;

namespace OPT
{

/**    
    @brief   Multithreaded SIMD-optimized CPU implemention of smallpt.
    @author  yakiimo02
    @date    2010/01/30
*/
class SmallPtCPU_MT
{
public:
    SmallPtCPU_MT();
    ~SmallPtCPU_MT();

    void Create( DataBufferDX11* pDataBuffer );
    void Render( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, DataBufferDX11* pDataBuffer );
    void Destroy();

    inline Vec* GetpBuffer() { return m_buffer; }
    inline Ray GetCam() const { return m_cam; }
    inline Vec GetCx() const { return m_cx; }
    inline Vec GetCy() const { return m_cy; }
    inline unsigned int GetWidth() const { return m_nWidth; }
    inline unsigned int GetHeight() const { return m_nHeight; }

protected:
    Vec*                            m_buffer;
    CTaskPool                       m_tasks;

    Ray                             m_cam; 
    Vec                             m_cx;
    Vec                             m_cy;

    unsigned int                    m_nWidth;
    unsigned int                    m_nHeight;
    bool                            m_bTaskStart;
};

}